// SelectInformationPage.cpp : implementation file
//

#include "stdafx.h"
#include "SelectLesson.h"
#include "SelectInformationPage.h"
#include "SelectInformationset.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSelectInformationPage property page

IMPLEMENT_DYNCREATE(CSelectInformationPage, CPropertyPage)

CSelectInformationPage::CSelectInformationPage() : CPropertyPage(CSelectInformationPage::IDD)
{
	//{{AFX_DATA_INIT(CSelectInformationPage)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CSelectInformationPage::~CSelectInformationPage()
{
}
BOOL CSelectInformationPage::OnCommand(WPARAM wParam, LPARAM lParam)
{
    SetModified(TRUE);
    return CPropertyPage::OnCommand(wParam, lParam);
}

void CSelectInformationPage::DoDataExchange(CDataExchange* pDX)
{  
	TRACE("Entering CSelectInformationPage::DoDataExchange -- %d\n",
          pDX->m_bSaveAndValidate);

	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSelectInformationPage)
	DDX_Control(pDX, IDC_LIST_SELECT_INFORMATION, m_ListCtrl_SelectInformation);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSelectInformationPage, CPropertyPage)
	//{{AFX_MSG_MAP(CSelectInformationPage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSelectInformationPage message handlers

BOOL CSelectInformationPage::OnInitDialog() 
{

	CPropertyPage::OnInitDialog();

    try
	{
		m_ListCtrl_SelectInformation.InsertColumn(0,_T("LessonNumber"),LVCFMT_LEFT,100,-1);
		m_ListCtrl_SelectInformation.InsertColumn(1,_T("StudentNumber"),LVCFMT_LEFT,100,-1);
	}
	catch(CDBException* pEx)
	{
		pEx->ReportError();
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CSelectInformationPage::OnSetActive() 
{
	m_ListCtrl_SelectInformation.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_TRACKSELECT);

	m_ListCtrl_SelectInformation.DeleteAllItems();
	
	m_database=new CDatabase;
	if(!m_database->Open(_T( "SelectLesson Registration" ),\
		FALSE,FALSE, _T( "ODBC;" ),FALSE))
	{
		AfxMessageBox("ODBC Connection Faile!");
		return FALSE;
	}

	m_pSelectset=new CSelectInformationset(m_database);
	m_pSelectset->Open(CRecordset::dynaset,_T("Select * from SelectInformation"));
//	m_pSelectset->Open();
	short nFields = m_pSelectset->GetODBCFieldCount();

	CString strTemp;
	int j=0;
	while( !m_pSelectset->IsEOF() )
	{
		strTemp.Format(_T("%d"),m_pSelectset->m_LessonNumber);
		m_ListCtrl_SelectInformation.InsertItem(j,(LPCTSTR)strTemp,0);
		strTemp.Format(_T("%d"),m_pSelectset->m_StudentNumber);
		m_ListCtrl_SelectInformation.SetItemText(j,1,(LPCTSTR)strTemp);
		m_pSelectset->MoveNext();
		j++;
	}
	return CPropertyPage::OnSetActive();
}
